package model.commands.misc;

import model.Environment;
import model.Interpreter;
import model.commands.Command;


/**
 * Name:
 * TO commandName
 * [ parameter(s) ]
 * [ command(s) ]
 * 
 * Description:
 * assigns commands given in the second list to commandName using parameters
 * given in first list as variables
 * when commandName is used later in a program, any given values are assigned to
 * variables that can be accessed when the command list is run
 * returns 1 if command is successfully defined, otherwise 0
 * 
 * @author Erick Gonzalez
 */
public class ToCommand extends Command {
    private Interpreter myInterpreter;
    private String myCommandName;
    private String myCommandInfo;

    /**
     * 
     * @param interpreter an interpreter
     * @param commandName the name of a user defined command
     * @param commandInfo a string containing information about this command,
     *        including its parameter list, and the real command it is mapped
     *        to
     */
    public ToCommand(Interpreter interpreter,
                     String commandName,
                     String commandInfo) {
        myInterpreter = interpreter;
        myCommandName = commandName;
        myCommandInfo = commandInfo;
    }

    @Override
    public int evaluate(Environment e) {
        myInterpreter.makeUserDefinedCommand(myCommandName, myCommandInfo);
        return 1;
    }
}
